<template>
  <Card>
    <template #header>
      <p class="fs_14 flex" style="text-align: center; color: #cbd2d5">性别分布</p>
    </template>
    <div id="main" ref="main"></div>
  </Card>
</template>

<script lang="ts" setup>
import Card from "@/components/Card";
import { onMounted, ref } from "vue";
import * as echarts from "echarts";
import { echartsAutoPlay } from "@/utils/echarts";
const main = ref();

onMounted(() => {
  setEcharts();
});
function setEcharts() {
  var myChart = echarts.init(main.value);
  var option = {
    tooltip: {
      trigger: "axis",
      extraCssText: "z-index:999",
      confine: true,
      backgroundColor: "rgba(255,255,255,0.8)",
    },
    legend: {
      left: 0,
      textStyle: {
        color: "#C8EAF9",
      },
    },
    grid: {
      top: 50,
      left: 0,
      right: "5%",
      bottom: "0",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      data: ["女", "男"],
      axisLabel: {
        textStyle: {
          color: "#CBD2D5",
        },
        interval: 0,
        margin: 20,
      },
      axisLine: {
        lineStyle: {
          color: "#CCCCCC",
        },
      },
      axisTick: {
        show: false,
      },
    },
    yAxis: [
      {
        type: "value",
        minInterval: 1,
        axisLabel: {
          textStyle: {
            color: "#CBD2D5",
          },
          formatter: "{value}%",
        },
        splitLine: {
          lineStyle: {
            color: "#222324",
          },
        },
        axisTick: {
          show: false,
        },
        axisLine: {
          show: false,
        },
      },
      {
        type: "value",
        name: "TGI",
        minInterval: 1,
        axisLabel: {
          textStyle: {
            color: "#CBD2D5",
          },
        },
        splitLine: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        axisLine: {
          show: false,
        },
      },
    ],
    series: [
      {
        name: "去有风的地方",
        data: [60, 42],
        type: "bar",
        barWidth: 20,
        itemStyle: {
          borderRadius: 20,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "#2CCCFA" },
            { offset: 1, color: "#586BFB" },
          ]),
        },
      },
      {
        name: "全网分布",
        barWidth: 20,
        data: [20, 32],
        type: "bar",
        itemStyle: {
          borderRadius: 20,
          color: "#273237",
        },
      },
      {
        name: "TGI",
        data: [720, 732],
        type: "line",
        yAxisIndex: 1,
        lineStyle: {
          color: "#2BCCC5",
        },
        itemStyle: { opacity: 0 },
      },
    ],
  };

  myChart.setOption(option);
  echartsAutoPlay(option, myChart);
}
</script>

<style lang="less" scoped>
#main {
  width: 100%;
  height: 100%;
}
</style>
